var upload = layui.upload;
$(document).ready(function() {

    //监听表单提交
    layui.form.on('submit(submitBtn)', function(data){
        $.post('/banner/add', $("#dataForm").serialize(), function(result) {
            if (200 == result.code) {
                close();
                parent.layui.table.reload('bannerTable');
            } else {
                layer.alert("保存失败");
            }
        });
        return false;
    });
});

//执行实例
var uploadInst = upload.render({
    elem: '#bannerUpload' //绑定元素
    ,url: '/file/upload' //上传接口
    ,accept: 'images'
    ,done: function(res){
        if (200 == res.code) {
            $('#showUrl').attr('src', res.data);
            $('#imageUrl').val(res.data);
        } else {
            layer.alert(res.msg);
        }
    }
    ,error: function(){
        //请求异常回调
    }
});

/**
 * 关闭当前窗口
 */
function close() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}